package com.rd.student.jiaji.class3.wangyanbo.task25;

import java.io.*;

public class TestCopy {
    public static void main(String[] args) throws Exception {
        File srcFile = new File("stream.txt");
        File destFile = new File("streamCopy.txt");
        copyFily(srcFile, destFile);
    }

    public static void copyFily(File srcFile, File destFile) throws Exception {
        //源文件是存在的 目标文件不一定存在
        if (!destFile.exists()) {
            destFile.createNewFile();
        }
        //先从源文件中读取数据 再将数据写入到目标文件中
        InputStream is = new FileInputStream(srcFile);
        byte[] byteArr = new byte[(int) srcFile.length()];
        is.read(byteArr);
        String content = new String(byteArr);

        OutputStream os = new FileOutputStream(destFile);
        byte[] byteArr1 = content.getBytes();
        os.write(byteArr1);

        os.close();
        is.close();
    }
}
